package com.lianqu1990.morphling.dao.jpa.entity;
// Generated 2017-10-21 13:17:01 by Hibernate Tools 4.3.5.Final

import com.lianqu1990.morphling.dao.jpa.core.AbstractJsonType;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.Type;

import javax.persistence.*;
import java.io.Serializable;
import java.sql.Types;
import java.util.List;
import java.util.Map;

import static javax.persistence.GenerationType.IDENTITY;

/**
 * Env generated by hbm2java
 */
@Data
@AllArgsConstructor
@NoArgsConstructor

@Entity
@DynamicInsert
@DynamicUpdate
@Table(name = "env")
public class Env implements java.io.Serializable {
    private static final long serialVersionUID = 1L;

    private Integer id;
    private String key;
    private String name;
    private boolean prod;
    private EnvProperties properties;

    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "id", unique = true, nullable = false)
    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Column(name = "key", unique = true, nullable = false, length = 20)
    public String getKey() {
        return this.key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    @Column(name = "name", nullable = false, length = 50)
    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name = "is_prod", nullable = false)
    public boolean isProd() {
        return prod;
    }

    public void setProd(boolean prod) {
        this.prod = prod;
    }

    @Column(name = "settings", length = 65535)
    @Type(type = "com.lianqu1990.morphling.dao.jpa.entity.Env$EnvJsonType")
    public EnvProperties getProperties() {
        return this.properties;
    }

    public void setProperties(EnvProperties properties) {
        this.properties = properties;
    }


    public static class EnvJsonType extends AbstractJsonType {
        private static final long serialVersionUID = 1L;

        @Override
        public int getSqlType() {
            return Types.LONGVARCHAR;
        }

        @Override
        public Class getJavaType() {
            return EnvProperties.class;
        }
    }


    @Data
    public static class EnvProperties implements Serializable{
        private static final long serialVersionUID = 1L;

        private Map<Integer,RedisDataSource> redises;

        private List<String> etcds;

        private String configPortal;

    }

    @Data
    public static class RedisDataSource implements Serializable {
        private static final long serialVersionUID = 1L;
        private String name;
        private RedisType type;
        private String address;
    }


    public enum RedisType {
        NORMAL,
        SENTINAL,
        CLUSTER
    }

}
